import * as func from "./func.js"
export default {
  name: '',
  props: {
    formData:{
      type: Array,
      default: () => []
    },
    item: {
      type: Object,
      default: () => {}
    },
  },
  components:{},
  data(){
    return {
      // tableHead: [
      //   {title: '药物名称', key: 'name', align:'center', slot: 'name', minWidth: 180},
      //   {title: '用法', key: 'useage', align:'center', slot: 'useage', minWidth: 200},
      //   {title: '用量', key: 'dosage', align:'center', slot: 'dosage', minWidth: 420},
      //   {title: '用药时间', key: 'time', align:'center', slot: 'time', width: 150},
      //   {title: '操作', key: 'action', align:'center', slot: 'action', width: 80, fixed: 'right'},
      // ],
      // tableData: [{name: '',useage: '', useageOther: '', frequency: '',frequencyOther: '',dosage: '', dosageUnit:'', dosageUniteOther: '',time:'', timeUnit: '',}],
      tableData: [],
      // pageObj: {
      //   page: 1,
      //   pageSize: 9999,
      //   totalCount: 0,
      // },
      useageList: [
        {id:'1', name: '口服'},{id:'2', name: '直肠用药'},{id:'3', name: '舌下用药'},{id:'4', name: '注射用药'},{id:'5', name: '吸入用药'},
        {id:'6', name: '局部用药'},{id:'0', name: '其他'}
      ],
      frequencyList: [
        {id:'1', name: '一天一次'},{id:'2', name: '一天两次'},{id:'3', name: '一天三次'},{id:'4', name: '一天四次'},{id:'5', name: '12小时一次'},
        {id:'6', name: '1小时一次'},{id:'7', name: '3小时一次'},{id:'8', name: '6小时一次'},{id:'9', name: '隔天一次'},{id:'10', name: '一周一次'},
        {id:'11', name: '一周两次'},{id:'12', name: '睡前服用'},{id:'13', name: '立即服用'},{id:'0', name: '其他'}
      ],
      dosageUnitList:[
        {id: '1', name: '片'}, {id: '2', name: '粒'}, {id: '3', name: '丸'}, {id: '4', name: '枚'}, {id: '5', name: '袋'},
        {id: '6', name: 'g'}, {id: '7', name: 'mg'}, {id: '8', name: '支'}, {id: '9', name: '瓶'}, {id: '10', name: 'ml'},
        {id: '11', name: '包'}, {id: '12', name: '盒'}, {id: '13', name: '管'}, {id: '14', name: '个'}, {id: '15', name: 'U'},
        {id: '16', name: 'ku'}, {id: '0', name: '其他'},
      ],
      timeUnitList: [
        {id: '1', name: '年'},{id: '2', name: '月'},{id: '3', name: '周'},{id: '4', name: '日'},
      ]
    }
  },
  watch: {
    item:{
      handler: function(newVal, oldVal) {
        // console.log(newVal)
        if(newVal){
          const {value} = newVal
          let tableData = JSON.parse(value) || []
          this.tableData = tableData.map(v => {
            v._useage = this.useageList.find(k => k.id == v.useage)['name']
            v._frequency = this.frequencyList.find(k => k.id == v.frequency)['name']
            v._dosageUnit = this.dosageUnitList.find(k => k.id == v.dosageUnit)['name']
            v._timeUnit = this.timeUnitList.find(k => k.id == v.timeUnit)['name']
            return v
          })
          // console.log(this.tableData)
        }
      },
      deep: true, // 监听深层对象
      immediate: true, // 会在页面渲染之前， 先执行一遍这个监听
    }
  },
  methods:{
    ...func,
  },
  created(){
    
  },
  mounted(){
    
  },
}